#include "projectitem.h"
#include "ui_projectitem.h"

ProjectItem::ProjectItem(QString id,QWidget *parent) :
    QWidget(parent),
    strID(id),
    ui(new Ui::SceneItem)
{
    ui->setupUi(this);
    ui->label_name->setText(strID);
    sceneWidget = new SceneProject(this);
}

ProjectItem::~ProjectItem()
{
    delete ui;
}
SceneProject* ProjectItem::getScene()
{
    return sceneWidget;
}

void ProjectItem::paintEvent(QPaintEvent *)
{
    //绘制准备工作,启用反锯齿
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    if(isFocus)
    {
        //绘制边框
        painter.setPen(QPen(5));
        painter.setBrush(Qt::NoBrush);
        painter.drawRect(0, 0, this->width(),this->height());
    }
}
#include <QMouseEvent>
void ProjectItem::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::RightButton)
        showMenu(mapToGlobal(event->pos()));
    else
        clickThis(strID);
}

#include <QMenu>
void ProjectItem::showMenu(const QPoint &pos)
{
    QMenu menu;
    menu.addAction("删除",[=](){
        deleteThis(strID);
    });
    //===================
    menu.exec(pos);
}

void ProjectItem::focusInEvent(QFocusEvent *e)
{
    Q_UNUSED(e)
    isFocus = 1;
    this->update();
}

void ProjectItem::focusOutEvent(QFocusEvent *e)
{
    Q_UNUSED(e)
    isFocus = 0;
    this->update();
}

void ProjectItem::resizeEvent(QResizeEvent *event)
{
    int size = event->size().width();
    if(size > event->size().height())
        size = event->size().height();
    resize(size,size);
}


